#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int hash[128] = { 0 };
        int ret = 0;
        int right = 0, left = 0;

        int n = s.size();
        for (; right < n; right++)
        {
            hash[s[right]]++;

            while (hash[s[right]] > 1)
                hash[s[left++]]--;

            ret = max(ret, right - left + 1);
        }

        return ret;
    }
};